<div class="hp-tab-newprd">
    <?php if(!is_iframe()){?>
    <ul class="j-sw-nav">
        <li class="newprd-s1 tab-li on"><a>绑定手机号</a></li>
    </ul>
    <div class="table-div">
        <?php }?>
        <div class="small-select small-input column" style="clear:both">
            <div class="form-label"><span style="color: red; font-size: 16px"> * </span>手机号码</div><?php print render( $form['cell']); ?>
        </div>
        <div class="small-select small-input column" style="clear:both">
            <div class="form-label"><span style="color: red; font-size: 16px"> * </span>图形验证码</div><div style="float: left; margin-right: 15px;"><?php print render($form['graph_code']); ?><?php print render($form['refresh_graph_code']); ?></div>
        </div>
        <div class="small-select small-input column" style="clear:both">
            <div class="form-label"><span style="color: red; font-size: 16px"> * </span>短信验证码</div><div style="float: left; margin-right: 15px;"><?php print render( $form['sms_code']); ?></div>
            <?php print render( $form['sms_send']);
                   print render( $form['sms_msg']); ?>
        </div>
        <div class="add-submit" style="margin-left: 130px;"><?php print render($form['submit']); ?></div>
    </div>
</div>

<?php print drupal_render_children($form); ?>


<script>
    jQuery('input[name="cell"]').blur(function(){


        var flag = 0;

//        if(!jQuery('input[name="farmer_name"]').val() || !jQuery('input[name="gender"]').val() || !jQuery('select[name="province"]').val() || !jQuery('select[name="city"]').val() || !jQuery('select[name="county"]').val() || !jQuery('input[name="details"]').val()){
//            flag = 1;
//            alert("请将必填项填写完整！")
//            return false;
//        }

        if(jQuery('input[name="cell"]').val()) {
            jQuery('input[name="sms_code"]').blur(function(){
                if (!jQuery('input[name="sms_code"]').val()) {
                    flag = 1;
                    alert("请填写短信验证码！");
                    return false;
                } else {
                    if (window.location.host == 'www.metercomm.com.cn') {
                        var url = '/nonghua/api/sms/check';
                    } else {
                        var url = '/api/sms/check';
                    }
                    jQuery.ajax({
                        url: url,
                        data: "checkDigit=" + jQuery('input[name="sms_code"]').val(),
                        type: 'post',
                        datatype: 'json',
                        async: false,
                        success: function (data) {
                            if (data.sms_check) {
                                //校验码成功
                                jQuery('input[name="is_bind"]').val('1');
                            } else {
                                flag = 1;
                                if (data.error == 1) {
                                    alert("校验码过期！");
                                } else if (data.error == 2) {
                                    alert("校验码错误！");
                                }

                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            flag = 1;
                            alert('textStatus:' + textStatus + XMLHttpRequest.status + errorThrown);
                        },

                    });
                }
            })
        }
    })
</script>
